<%@ page language="java" import="java.util.*,java.sql.*,connBean.*" pageEncoding="utf-8"%>
<%@page import="com.jspsmart.upload.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<jsp:useBean id="db" class="connBean.ConnDB" scope="page">
</jsp:useBean>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>保存页面</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
<% 
  request.setCharacterEncoding("utf-8");
  SmartUpload upload =new SmartUpload();
  upload.initialize(pageContext);
  upload.setMaxFileSize(2000000000);
  upload.setAllowedFilesList("jpg,JPG,gif,png");
  upload.setDeniedFilesList("exe,bat,jsp,js,htm,html");
  upload.upload();
  upload.save("/images");

  
  String adminname=upload.getRequest().getParameter("adminname");
  String psw=upload.getRequest().getParameter("password");
  String phone=upload.getRequest().getParameter("phone");
  String Email=upload.getRequest().getParameter("Email");
  String filename=upload.getFiles().getFile(0).getFileName();
        if(filename.equals("")||filename==null){
filename="defaultheader.jpg";
}
  
  
  db.OpenConn();
db.createStmt();
  String sql1="select * from admin where a_name="+"'"+adminname+"'";
  ResultSet rs=db.Query(sql1);
  
 if(rs.next()){
  %>
用户名已存在，等待3秒后返回。
 <%
 response.setHeader("Refresh","3;URL=addadmin.jsp");
 rs.close();
 } 
  else{
   String sql="insert into admin(a_name,a_pass,a_phone,a_email,a_header) values('"+adminname+"','"+psw+"','"+phone+"','"+Email+"','"+filename+"')";//定义插入SQL语句
   System.out.print(sql);


int result=db.Update(sql);

 if(result==1){ 
 response.sendRedirect("selectadmin.jsp");//执行插入成功跳转
 }else{
 %>
 插入失败，等待5秒后返回。
 <%
 response.setHeader("Refresh","5;URL=addadmin.jsp");//执行插入失败跳转
 }
 db.closeStmt();
 db.closeConn();
}%>  

  </body>
  <script language="javascript">
    function changeF()
    {
            // 从下面的赋值可以的值，你在action 中只要得到name =“ccdd” 的值就可以了。
            document.getElementById('ccdd').value=document.getElementById('aabb').options[document.getElementById('aabb').selectedIndex].value;
    }
</script>
</html>
